<template>
  <div>
    <div>
      <el-button type="text" @click="centerDialogVisible = true"></el-button>
      <el-dialog
        title="选择类型"
        :visible.sync="centerDialogVisible"
        :close-on-click-modal="false"
        :show-close="false"
        width="40%"
        right>
        <div style="width: 100%" >
        <span v-for="todo in workOrderTypeList" style="margin-top: 5px;margin-right: 5px">
          <el-button plain size="small" style="margin-top: 10px" @click='typePush(todo)'>{{todo.modelPName}}<i class="el-icon-document el-icon--right"></i></el-button>
        </span>
        </div>
        <span slot="footer" class="dialog-footer">
        <!--<el-button @click="centerDialogVisible = false" size="small">取 消</el-button>-->
          <!--<el-button type="primary" @click="centerDialogVisible = false" size="small">确 定</el-button>-->
      </span>
      </el-dialog>
    </div>
    <div>

    </div>
  </div>
</template>

<script>
  import QS from 'qs';
  import axios from 'axios';
  import { mapState } from 'vuex';


    export default {
      name: "orderWindows",
      computed: {
        ...mapState([
          'workOrderTypeList',
          'creatWorkOrder'
        ]),
      },
      data() {
        return {
          centerDialogVisible: false,
        };
      },
      methods:{
        opendialog(){
          this.centerDialogVisible = true;
        },
        selectBindCase(){
          var that = this;
          that.$store.commit('workOrderTypeListClear');
          axios.post('/api/case/selectBindCaseType')
            .then(function (binddata) {
              var BindCaseData = binddata.data;
              var BindCaseList = binddata.data.data;
              for (var i=0; i<BindCaseList.length; i++){
                var sypeOption = BindCaseList[i];
                that.$store.commit('workOrderTypeListPush',sypeOption)
              };
              console.log("52"+JSON.stringify(that.workOrderTypeList));
            })
        },
        typeList(){
          var that = this;
          console.log("61"+JSON.stringify(this.workOrderTypeList.length))
          // for (var i=0; i<){}
        },
        typePush(todo){
          var that = this;
          var typeData = {};
          //清除creatWorkOrderPush已经添加的数据
          that.$store.commit('creatWorkOrderClear');
            typeData.modelPid = todo.modelPid;
            axios.post('/api/case/getCreateCaseModelAttrs',QS.stringify(typeData))
              .then(function (returnData) {
                var typeDataCode = returnData.data.code;
                var typeData = returnData.data.data;
                var typeGroupList = typeData.cmdbModelVO.propertyGroupVOS;
                var typeDataListLength = typeData.cmdbModelVO.propertyGroupVOS.length;
                if (typeDataCode == "200"){
                  that.centerDialogVisible = false;
                  for (var i=0; i<typeDataListLength; i++) {
                    var typeDataList = typeGroupList[i].propertyVOS;
                    for (var j=0; j<typeDataList.length; j++) {
                      var typeDataObject = {};
                          typeDataObject.name = typeDataList[j].name;
                          typeDataObject.type = typeDataList[j].type;
                          typeDataObject.detail = JSON.parse(typeDataList[j].detail);
                          typeDataObject.id = typeDataList[j].id;
                          typeDataObject.modolId = typeData.cmdbModelVO.id;
                          typeDataObject.caseId = typeData.caseId;
                          typeDataObject.modelPid = typeData.modelPid;
                          typeDataObject.workflowId = typeData.workflowId;
                          typeDataObject.mustFlag = typeDataList[j].mustFlag;
                      that.$store.commit('creatWorkOrderPush',typeDataObject);
                      that.$store.commit('changeStep1');
                    };
                    console.log("172"+ JSON.stringify(that.creatWorkOrder));
                  };
                } else {
                  console.log("错误代码："+typeDataCode);
                };
              })
          // alert(todo.modelPid);
        },
        // closeRouter(){   //窗口跳转
        //   var that = this;
        //   that.$router.push({ path: '/myWorkOrder/thisWorkOrder' });
        // },
      },
      mounted(){
        this.selectBindCase();
        this.typeList();
      },
      beforeMount(){
        this.opendialog();
      },
    }
</script>

<style scoped>

</style>
